using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using System.Data;
using System.Data.SqlClient;
using System.Data.Sql;

namespace DAO
{
    public class DatHangDAO
    {

        public static DataTable LayThongTinSua()
        {
            DataTable dt = SqlDataAccessHelper.ExecuteQuery("spLayThongTinLoaiSua", null);
            return dt;
        }
        public static DataTable InThongTinHoaDon(string MaKH)
        {
            List<SqlParameter> sqlParams = new List<SqlParameter>();
            sqlParams.Add(new SqlParameter("@MaKH", MaKH));
            DataTable dt = SqlDataAccessHelper.ExecuteQuery("spInThongTinHoaDon", sqlParams);
            return dt;
        }

        public static bool KiemTraKhachHang(String MaKH)
        {
            bool result = false;
            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MaKH", MaKH));
                DataTable dt = SqlDataAccessHelper.ExecuteQuery("spKiemTraNhapKhachHang", sqlParams);
                if (dt.Rows.Count >= 1)
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
        public static bool NhapDatHang(DatHangDTO dh)
        {
            bool result = false;
            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MaHoaDon", dh.MaHoaDon));
                sqlParams.Add(new SqlParameter("@MaKH", dh.MaKH));
                sqlParams.Add(new SqlParameter("@NgayGiao", dh.NgayGiao));
                sqlParams.Add(new SqlParameter("@NgayLapHoaDon", dh.NgayLapHoaDon));
                sqlParams.Add(new SqlParameter("@TrangThaiGiao", dh.TrangThaiGiao));               
                // Call Store Procedure
                int n = SqlDataAccessHelper.ExecuteNoneQuery("spInsertHoaDon", sqlParams);
                if (n == 1)
                    result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }


        public static void NhapChiTietHoaDon(DatHangDTO dh)
        {
            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MaHoaDon", dh.MaHoaDon));
                sqlParams.Add(new SqlParameter("@MaHangHoa", dh.MaHangHoa));
                sqlParams.Add(new SqlParameter("@SoLuong", dh.SoLuong));
                // Call Store Procedure
                SqlDataAccessHelper.ExecuteNoneQuery("spInsertChiTietHoaDon", sqlParams);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

    }
}
